import { Component, OnInit } from '@angular/core';
import { ExtractAccountService } from './extract-account.service';
import { DataService } from '../../../../services/data.service';

@Component({
  selector: 'app-extract-account',
  templateUrl: './extract-account.component.html',
  styleUrls: ['./extract-account.component.scss'],
  providers: [ExtractAccountService]
})
export class ExtractAccountComponent implements OnInit {
  public optionModel: any = '1';
  public extractAccountInfo: any;
  //保存条目post数据
  public addEntryPostBody: any = {
    sAccRate: "",
    sAccRateExp: "",
    sPayFreBasic: "",
    sPayFreBasicExp: "",
    sAccCon: "",
    sAccConExp: "",
    sPayConBasic: "",
    sPayConBasicExp: "",
    sPayProBasic: "",
    sPayProBasicExp: "",
    sAch: "",
    sAchExp: "",
    sAccPro: "",
    sAccProExp: "",
    sAccLimit: "",
    sAccLimitExp: "",
    sAccFormula: "",
    sAcclFormulaExp: "",
    sAccFre: "",
    sAccFreExp: "",
    sPayFre: "",
    sPayFreExp: "",
    sPayCon: "",
    sPayConExp: "",
    sPayPro: "",
    sPayProExp: "",
    sCommFeeinfo: "",
    sCommFeeinfoExp: "",
    sTrusteeFeeinfo: "",
    sTrusteeFeeinfoExp: ""

  }
  constructor(
    public extractAccountService: ExtractAccountService,
    public dataService:DataService
  ) { }

  ngOnInit() {
    if (this.extractAccountInfo.sAccountItem == '1') {
      this.getSingleServiceInfo();
    }
  }
  // ngDoCheck() {
  //   console.log(this.addEntryPostBody)
  // }
  //保存条目
  saveEntry() {
    let that = this;
    // console.log("啊哈哈哈哈哈" + this.addEntryPostBody)
    window["swal"]({
      title: "注意",
      text: "是否确定保存条目",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          if (that.extractAccountInfo.sAccountItem == '0') {
            that.addEntryPostBody['sAccountItem'] = '1';
            // console.log("------------sadasd---------------")
            // console.log(that.addEntryPostBody)
            that.extractAccountService.save(that.addEntryPostBody, that.extractAccountInfo.nFundNo).subscribe(data => {
              if (data) {
                that.dataService.entryEmitter.emit('extractAccount');
                window['swal']("提示", "保存条目成功!", "success");
              }
            })
          } else {
            that.editAccountEntry();
          }

        }
      })
  }
  //查询-单个核算条目条目内容（根据FundNo）
  getSingleServiceInfo() {
    this.addEntryPostBody = {};
    this.extractAccountService.getSingleInfo(this.extractAccountInfo.nFundNo).subscribe(data => {
      if (data) {
        this.addEntryPostBody = data;

        // console.log(data);
      }
    })
  }
  //更新-核算条目-单个
  editAccountEntry() {
    this.extractAccountService.edit(this.addEntryPostBody).subscribe(data => {
      if (data) {
        window['swal']("提示", "修改条目成功!", "success")
      }
    })
  }

}